home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / CONFIG.C < prev    next >
C/C++ Source or Header  |  1991-12-08  |  14KB  |  404 lines

  1. /*
  2.  * config.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  */
  8.  
  9. /*
  10.  * This program is intended to help you determine how to configure the JPEG
  11.  * software for installation on a particular system.  The idea is to try to
  12.  * compile and execute this program.  If your compiler fails to compile the
  13.  * program, make changes as indicated in the comments below.  Once you can
  14.  * compile the program, run it, and it will tell you how to set the various
  15.  * switches in jconfig.h and in your Makefile.
  16.  *
  17.  * This could all be done automatically if we could assume we were on a Unix
  18.  * system, but we don't want to assume that, so you'll have to edit and
  19.  * recompile this program until it works.
  20.  *
  21.  * As a general rule, each time you try to compile this program,
  22.  * pay attention only to the *first* error message you get from the compiler.
  23.  * Many C compilers will issue lots of spurious error messages once they
  24.  * have gotten confused.  Go to the line indicated in the first error message,
  25.  * and read the comments preceding that line to see what to change.
  26.  *
  27.  * Almost all of the edits you may need to make to this program consist of
  28.  * changing a line that reads "#define SOME_SYMBOL" to "#undef SOME_SYMBOL",
  29.  * or vice versa.  This is called defining or undefining that symbol.
  30.  */
  31.  
  32.  
  33. /* First we must see if your system has the include files we need.
  34.  * We start out with the assumption that your system follows the ANSI
  35.  * conventions for include files.  If you get any error in the next dozen
  36.  * lines, undefine INCLUDES_ARE_ANSI.
  37.  */
  38.  
  39. #define INCLUDES_ARE_ANSI    /* replace 'define' by 'undef' if error here */
  40.  
  41. #ifdef INCLUDES_ARE_ANSI    /* this will be skipped if you undef... */
  42. #include <stdio.h>        /* If you ain't got this, you ain't got C. */
  43. #ifdef __SASC            /* Amiga SAS C provides size_t in stddef.h. */
  44. #include <stddef.h>        /* (They are wrong...) */
  45. #endif
  46. #include <string.h>        /* size_t might be here too. */
  47. typedef size_t my_size_t;    /* The payoff: do we have size_t now? */
  48. #include <stdlib.h>        /* Check other ANSI includes we use. */
  49. #endif
  50.  
  51.  
  52. /* If your system doesn't follow the ANSI conventions, we have to figure out
  53.  * what it does follow.  If you didn't get an error before this line, you can
  54.  * ignore everything down to "#define HAVE_ANSI_DEFINITIONS".
  55.  */
  56.  
  57. #ifndef INCLUDES_ARE_ANSI    /* skip these tests if INCLUDES_ARE_ANSI */
  58.  
  59. #include <stdio.h>        /* If you ain't got this, you ain't got C. */
  60.  
  61. /* jinclude.h will try to include <sys/types.h> if you don't set
  62.  * INCLUDES_ARE_ANSI.  We need to test whether that include file is provided.
  63.  * If you get an error here, undefine HAVE_TYPES_H.
  64.  */
  65.  
  66. #define HAVE_TYPES_H
  67.  
  68. #ifdef HAVE_TYPES_H
  69. #include <sys/types.h>
  70. #endif
  71.  
  72. /* We have to see if your string functions are defined by
  73.  * strings.h (BSD convention) or string.h (everybody else).
  74.  * We try the non-BSD convention first; define BSD if the compiler
  75.  * says it can't find string.h.
  76.  */
  77.  
  78. #undef BSD
  79.  
  80. #ifdef BSD
  81. #include <strings.h>
  82. #else
  83. #include <string.h>
  84. #endif
  85.  
  86. /* Usually size_t is defined in stdio.h, sys/types.h, and/or string.h.
  87.  * If not, you'll get an error on the "typedef size_t my_size_t;" line below.
  88.  * In that case, you'll have to search through your system library to
  89.  * figure out which include file defines "size_t".  Look for a line that
  90.  * says "typedef something-or-other size_t;" (stddef.h and stdlib.h are
  91.  * good places to look first).  Then, change the line below that says
  92.  * "#include <someincludefile.h>" to instead include the file
  93.  * you found size_t in, and define NEED_SPECIAL_INCLUDE.
  94.  */
  95.  
  96. #undef NEED_SPECIAL_INCLUDE    /* assume we DON'T need it, for starters */
  97.  
  98. #ifdef NEED_SPECIAL_INCLUDE
  99. #include <someincludefile.h>
  100. #endif
  101.  
  102. typedef size_t my_size_t;    /* The payoff: do we have size_t now? */
  103.  
  104.  
  105. #endif /* INCLUDES_ARE_ANSI */
  106.  
  107.  
  108.  
  109. /* The next question is whether your compiler supports ANSI-style function
  110.  * definitions.  You need to know this in order to choose between using
  111.  * makefile.ansi and using makefile.unix.
  112.  * The #define line below is set to assume you have ANSI function definitions.
  113.  * If you get an error in this group of lines, undefine HAVE_ANSI_DEFINITIONS.
  114.  */
  115.  
  116. #define HAVE_ANSI_DEFINITIONS
  117.  
  118. #ifdef HAVE_ANSI_DEFINITIONS
  119. int testfunction (int arg1, int * arg2); /* check prototypes */
  120.  
  121. struct methods_struct {        /* check method-pointer declarations */
  122.   int (*error_exit) (char *msgtext);
  123.   int (*trace_message) (char *msgtext);
  124. };
  125.  
  126. int testfunction (int arg1, int * arg2) /* check definitions */
  127. {
  128.   return arg2[arg1];
  129. }
  130. #endif
  131.  
  132.  
  133. /* Now we want to find out if your compiler knows what "unsigned char" means.
  134.  * If you get an error on the "unsigned char un_char;" line,
  135.  * then undefine HAVE_UNSIGNED_CHAR.
  136.  */
  137.  
  138. #define HAVE_UNSIGNED_CHAR
  139.  
  140. #ifdef HAVE_UNSIGNED_CHAR
  141. unsigned char un_char;
  142. #endif
  143.  
  144.  
  145. /* Now we want to find out if your compiler knows what "unsigned short" means.
  146.  * If you get an error on the "unsigned short un_short;" line,
  147.  * then undefine HAVE_UNSIGNED_SHORT.
  148.  */
  149.  
  150. #define HAVE_UNSIGNED_SHORT
  151.  
  152. #ifdef HAVE_UNSIGNED_SHORT
  153. unsigned short un_short;
  154. #endif
  155.  
  156.  
  157. /* Now we want to find out if your compiler understands type "void".
  158.  * If you get an error anywhere in here, undefine HAVE_VOID.
  159.  */
  160.  
  161. #define HAVE_VOID
  162.  
  163. #ifdef HAVE_VOID
  164. typedef void * void_ptr;    /* check void * */
  165. typedef void (*void_func) ();    /* check ptr to function returning void */
  166.  
  167. void testfunction2 (arg1, arg2)    /* check void function result */
  168.      void_ptr arg1;
  169.      void_func arg2;
  170. {
  171.   char * locptr = (char *) arg1; /* check casting to and from void * */
  172.   arg1 = (void *) locptr;
  173.   (*arg2) (1, 2);        /* check call of fcn returning void */
  174. }
  175. #endif
  176.  
  177.  
  178. /* Now we want to find out if your compiler knows what "const" means.
  179.  * If you get an error here, undefine HAVE_CONST.
  180.  */
  181.  
  182. #define HAVE_CONST
  183.  
  184. #ifdef HAVE_CONST
  185. static const int carray[3] = {1, 2, 3};
  186.  
  187. int testfunction3 (arg1)
  188.      const int arg1;
  189. {
  190.   return carray[arg1];
  191. }
  192. #endif
  193.  
  194.  
  195.  
  196. /************************************************************************
  197.  *  OK, that's it.  You should not have to change anything beyond this
  198.  *  point in order to compile and execute this program.  (You might get
  199.  *  some warnings, but you can ignore them.)
  200.  *  When you run the program, it will make a couple more tests that it
  201.  *  can do automatically, and then it will print out a summary of the changes
  202.  *  that you need to make to the makefile and jconfig.h.
  203.  ************************************************************************
  204.  */
  205.  
  206.  
  207. static int any_changes = 0;
  208.  
  209. int new_change ()
  210. {
  211.   if (! any_changes) {
  212.     printf("\nMost of the changes recommended by this program can be made either\n");
  213.     printf("by editing jconfig.h, or by adding -Dsymbol switches to the CFLAGS\n");
  214.     printf("line in your Makefile.  (Some PC compilers expect /Dsymbol instead.)\n");
  215.     printf("The CFLAGS method is simpler, but if your system doesn't use makefiles,\n");
  216.     printf("or if your compiler doesn't support -D, then you must change jconfig.h.\n");
  217.     any_changes = 1;
  218.   }
  219.   printf("\n");            /* blank line before each problem report */
  220.   return 0;
  221. }
  222.  
  223.  
  224. int test_char_sign (arg)
  225.      int arg;
  226. {
  227.   if (arg == 189) {        /* expected result for unsigned char */
  228.     new_change();
  229.     printf("You should add -DCHAR_IS_UNSIGNED to CFLAGS,\n");
  230.     printf("or else remove the /* */ comment marks from the line\n");
  231.     printf("/* #define CHAR_IS_UNSIGNED */  in jconfig.h.\n");
  232.     printf("(Be sure to delete the space before the # character too.)\n");
  233.   }
  234.   else if (arg != -67) {    /* expected result for signed char */
  235.     new_change();
  236.     printf("Hmm, it seems 'char' is less than eight bits wide on your machine.\n");
  237.     printf("I fear the JPEG software will not work at all.\n");
  238.   }
  239.   return 0;
  240. }
  241.  
  242.  
  243. int test_shifting (arg)
  244.      long arg;
  245. /* See whether right-shift on a long is signed or not. */
  246. {
  247.   long res = arg >> 4;
  248.  
  249.   if (res == 0x80817F4L) {    /* expected result for unsigned */
  250.     new_change();
  251.     printf("You must add -DRIGHT_SHIFT_IS_UNSIGNED to CFLAGS,\n");
  252.     printf("or else remove the /* */ comment marks from the line\n");
  253.     printf("/* #define RIGHT_SHIFT_IS_UNSIGNED */  in jconfig.h.\n");
  254.   }
  255.   else if (res != -0x7F7E80CL) { /* expected result for signed */
  256.     new_change();
  257.     printf("Right shift isn't acting as I expect it to.\n");
  258.     printf("I fear the JPEG software will not work at all.\n");
  259.   }
  260.   return 0;
  261. }
  262.  
  263.  
  264. int main (argc, argv)
  265.      int argc;
  266.      char ** argv;
  267. {
  268.   char signed_char_check = (char) (-67);
  269.  
  270.   printf("Results of configuration check for Independent JPEG Group's software:\n");
  271.   printf("\nIf there's not a specific makefile provided for your compiler,\n");
  272. #ifdef HAVE_ANSI_DEFINITIONS
  273.   printf("you should use makefile.ansi as the starting point for your Makefile.\n");
  274. #else
  275.   printf("you should use makefile.unix as the starting point for your Makefile.\n");
  276. #endif
  277.  
  278.   /* Check whether we have all the ANSI features, */
  279.   /* and whether this agrees with __STDC__ being predefined. */
  280. #ifdef __STDC__
  281. #define MY__STDC__    /* ANSI compilers won't allow redefining __STDC__ */
  282. #endif
  283.  
  284. #ifdef HAVE_ANSI_DEFINITIONS
  285. #ifdef HAVE_UNSIGNED_CHAR
  286. #ifdef HAVE_UNSIGNED_SHORT
  287. #ifdef HAVE_CONST
  288. #define HAVE_ALL_ANSI_FEATURES
  289. #endif
  290. #endif
  291. #endif
  292. #endif
  293.  
  294. #ifdef HAVE_ALL_ANSI_FEATURES
  295. #ifndef MY__STDC__
  296.   new_change();
  297.   printf("Your compiler doesn't claim to be ANSI-compliant, but it is close enough\n");
  298.   printf("for me.  Either add -D__STDC__ to CFLAGS, or add #define __STDC__ at the\n");
  299.   printf("beginning of jinclude.h (NOT jconfig.h).\n");
  300.   printf("Some compilers will not let you do this: they will complain that __STDC__\n");
  301.   printf("is a reserved name.  In that case you have a compiler that really is ANSI,\n");
  302.   printf("but you have to give it a special switch (often -ansi) to make it so.\n");
  303.   printf("Check your compiler documentation and add the proper switch to CFLAGS.\n");
  304. #define MY__STDC__
  305. #endif
  306. #else /* !HAVE_ALL_ANSI_FEATURES */
  307. #ifdef MY__STDC__
  308.   new_change();
  309.   printf("Your compiler claims to be ANSI-compliant, but it is lying!\n");
  310.   printf("Either add -U__STDC__ to CFLAGS, or add #undef __STDC__\n");
  311.   printf("at the beginning of jinclude.h (NOT jconfig.h).\n");
  312. #undef MY__STDC__
  313. #endif
  314. #endif /* HAVE_ALL_ANSI_FEATURES */
  315.  
  316. #ifndef MY__STDC__
  317.  
  318. #ifdef HAVE_ANSI_DEFINITIONS
  319.   new_change();
  320.   printf("You should add -DPROTO to CFLAGS, or else take out the several\n");
  321.   printf("#ifdef/#else/#endif lines surrounding #define PROTO in jconfig.h.\n");
  322.   printf("(Leave only one #define PROTO line.)\n");
  323. #endif
  324.  
  325. #ifdef HAVE_UNSIGNED_CHAR
  326. #ifdef HAVE_UNSIGNED_SHORT
  327.   new_change();
  328.   printf("You should add -DHAVE_UNSIGNED_CHAR and -DHAVE_UNSIGNED_SHORT\n");
  329.   printf("to CFLAGS, or else take out the #ifdef __STDC__/#endif lines\n");
  330.   printf("surrounding #define HAVE_UNSIGNED_CHAR and #define HAVE_UNSIGNED_SHORT\n");
  331.   printf("in jconfig.h.\n");
  332. #else /* only unsigned char */
  333.   new_change();
  334.   printf("You should add -DHAVE_UNSIGNED_CHAR to CFLAGS,\n");
  335.   printf("or else move #define HAVE_UNSIGNED_CHAR outside the\n");
  336.   printf("#ifdef __STDC__/#endif lines surrounding it in jconfig.h.\n");
  337. #endif
  338. #else /* !HAVE_UNSIGNED_CHAR */
  339. #ifdef HAVE_UNSIGNED_SHORT
  340.   new_change();
  341.   printf("You should add -DHAVE_UNSIGNED_SHORT to CFLAGS,\n");
  342.   printf("or else move #define HAVE_UNSIGNED_SHORT outside the\n");
  343.   printf("#ifdef __STDC__/#endif lines surrounding it in jconfig.h.\n");
  344. #endif
  345. #endif /* HAVE_UNSIGNED_CHAR */
  346.  
  347. #ifdef HAVE_CONST
  348.   new_change();
  349.   printf("You can delete the #define const line from jconfig.h.\n");
  350.   printf("(But things should still work if you don't.)\n");
  351. #endif
  352.  
  353. #endif /* MY__STDC__ */
  354.  
  355.   test_char_sign((int) signed_char_check);
  356.  
  357.   test_shifting(-0x7F7E80B1L);
  358.  
  359. #ifndef HAVE_VOID
  360.   new_change();
  361.   printf("You should add -Dvoid=char to CFLAGS,\n");
  362.   printf("or else remove the /* */ comment marks from the line\n");
  363.   printf("/* #define void char */  in jconfig.h.\n");
  364.   printf("(Be sure to delete the space before the # character too.)\n");
  365. #endif
  366.  
  367. #ifdef INCLUDES_ARE_ANSI
  368. #ifndef MY__STDC__
  369.   new_change();
  370.   printf("You should add -DINCLUDES_ARE_ANSI to CFLAGS, or else add\n");
  371.   printf("#define INCLUDES_ARE_ANSI at the beginning of jinclude.h (NOT jconfig.h).\n");
  372. #endif
  373. #else /* !INCLUDES_ARE_ANSI */
  374. #ifdef MY__STDC__
  375.   new_change();
  376.   printf("You should add -DNONANSI_INCLUDES to CFLAGS, or else add\n");
  377.   printf("#define NONANSI_INCLUDES at the beginning of jinclude.h (NOT jconfig.h).\n");
  378. #endif
  379. #ifdef NEED_SPECIAL_INCLUDE
  380.   new_change();
  381.   printf("In jinclude.h, change the line reading #include <sys/types.h>\n");
  382.   printf("to instead include the file you found size_t in.\n");
  383. #else /* !NEED_SPECIAL_INCLUDE */
  384. #ifndef HAVE_TYPES_H
  385.   new_change();
  386.   printf("In jinclude.h, delete the line reading #include <sys/types.h>.\n");
  387. #endif
  388. #endif /* NEED_SPECIAL_INCLUDE */
  389. #ifdef BSD
  390.   new_change();
  391.   printf("You should add -DBSD to CFLAGS, or else add\n");
  392.   printf("#define BSD at the beginning of jinclude.h (NOT jconfig.h).\n");
  393. #endif
  394. #endif /* INCLUDES_ARE_ANSI */
  395.  
  396.   if (any_changes) {
  397.     printf("\nI think that's everything...\n");
  398.   } else {
  399.     printf("\nI think jconfig.h is OK as distributed.\n");
  400.   }
  401.  
  402.   return any_changes;
  403. }
  404.